package org.kernely.test.security;

import org.kernely.ui.mvp.IKernelyView;

import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

/**
 * The SecurityView class
 */
@SuppressWarnings("serial")
public class SecurityView extends GridLayout implements IKernelyView{


	public final static Class<? extends IKernelyView> ID_VIEW = SecurityView.class;

	private TextField roleField;
	private NativeSelect rolesBox;
	private Button addRoleButton;

	/**
	 * This method initializes the View. No logic, only display.
	 */
	public SecurityView(){
		Panel northPanel = new Panel();
		Panel southPanel = new Panel();
		Panel eastPanel = new Panel();
		roleField = new TextField("Name of the role");
		roleField.setRequiredError("You must enter a name for the role.");
		roleField.setRequired(true);
		addRoleButton = new Button("Add this role");
		addRoleButton.setClickShortcut(KeyCode.ENTER);
		rolesBox = new NativeSelect();
		rolesBox.setCaption("Existing roles");
		this.setColumns(4);
		this.setRows(2);
		this.addComponent(northPanel,0,0);
		this.addComponent(southPanel,0,1);
		this.addComponent(eastPanel,1,0,3,1);
		northPanel.addComponent(new Label("Test Bundle security page"));
		southPanel.addComponent(new Label("Step 1 : Check the existing roles in database, by selecting the combo box."));
		southPanel.addComponent(new Label("Step 2 : Enter a name for a new role and click on the button to add the new role."));
		southPanel.addComponent(new Label("Step 3 : Check that the new role is now in the combo box."));
		southPanel.addComponent(new Label("Step 4 : Enter the same name and click on the button to add the role."));
		southPanel.addComponent(new Label("Step 5 : Check that the new role is not duplicated in the combo box."));
		southPanel.addComponent(new Label("Step 6 : Click on the Home button to go back home."));
		((VerticalLayout)eastPanel.getContent()).setSpacing(true);
		eastPanel.addComponent(rolesBox);
		eastPanel.addComponent(roleField);
		eastPanel.addComponent(addRoleButton);
		this.setSizeFull();
	}

	/**
	 * @see org.kernely.core.service.IKernelyView#getComponent()
	 */
	public final Component getComponent() {
		return this;
	}

	
	//Getters

	
	/**
	 * Gets the roleField
	 * @return the roleField
	 */
	public TextField getRoleField() {
		return roleField;
	}

	/**
	 * Gets the existingRolesBox
	 * @return the existingRolesBox
	 */
	public NativeSelect getRolesBox() {
		return rolesBox;
	}

	/**
	 * Gets the addRoleButton
	 * @return the addRoleButton
	 */
	public Button getAddRoleButton() {
		return addRoleButton;
	}
}

